

function checkPasswordStrength(password) {
    let strLength = 0;
    if (password.length >= 6) {
        strLength += 1;
    }
    if (/[a-z]/.test(password)) {
        strLength += 1;
    }
    if (/[A-Z]/.test(password)) {
        strLength += 1;
    }
    if (/[0-9]/.test(password)) {
        strLength += 1;
    }
    return strLength;
}

function formValidate() {
    let username = $("#userName").val();
    let password = $("#password").val();
    let age = $("#userAge").val();
    let enterPassword = $("#enterPassword").val();

    if (username === "" || password === "") {
        alert("用户名和密码是必填项");
        return false;
    }
    if (age =="") {
        alert("年龄是必填项");
        return false;
    }
    if (username.length < 6 || username.length > 10 ) {
        alert("用户名长度 必须在6-10位之间");
        return false;
    }
    if (enterPassword === "") {
        alert("确认密码不能为空");
        return false;
    }
    if (password!== enterPassword) {
        alert("密码和确认密码不一致");
        return false;
    }
    if (/[^a-zA-Z0-9]/.test(password)) {
        alert("密码不能包含特殊字符");
        return false;
    }
    if (password.length < 6 || password.length > 10) {
        alert("密码必须6-10位");
        return false;;
    }

    let passwordStrLength = checkPasswordStrength(password);
    if (passwordStrLength < 3) {
        alert("密码强度太弱，请包含字母、数字");
        return false;
    }

    return true;
}
